package org.qianye.soft.ext;

import javax.swing.SwingUtilities;

import org.divxdede.swing.busy.DefaultBusyModel;
import org.divxdede.swing.busy.JBusyComponent;
import org.divxdede.swing.busy.icon.InfiniteBusyIcon;
import org.divxdede.swing.busy.ui.BasicBusyLayerUI;

//import org.divxdede.swing.busy.DefaultBusyModel;
//import org.divxdede.swing.busy.JBusyComponent;
//import org.divxdede.swing.busy.icon.InfiniteBusyIcon;
//import org.divxdede.swing.busy.ui.BasicBusyLayerUI;

public class JLoadComponent extends JBusyComponent {

	private final DefaultBusyModel busyModel = new DefaultBusyModel();

	private boolean mask;

	/**
     *
     */
	public JLoadComponent() {
		BasicBusyLayerUI busyLayer = new BasicBusyLayerUI();
		busyLayer.setBusyIcon(new InfiniteBusyIcon());
		setBusyLayerUI(busyLayer);
		setBusyModel(busyModel);
	}

	/**
     *
     */
	public void mask() {
		mask(null);
	}

	/**
	 * @param message
	 */
	public void mask(String message) {
		if (!mask) {
			mask = true;
			setMaskMessage(message);

			busyModel.setBusy(true);

		}
	}

	/**
     *
     */
	public void unmask() {
		if (mask) {
			mask = false;
			setMaskMessage("");

			busyModel.setBusy(false);

		}
	}

	/**
	 * @return
	 */
	public String getMaskMessage() {
		return busyModel.getDescription();
	}

	/**
	 * @param maskMessage
	 */
	public void setMaskMessage(String maskMessage) {
		this.busyModel.setDescription(maskMessage);
	}
}
